package com.cheems.controller;

import com.cheems.entity.Result.Result;
import com.cheems.utils.AliOSSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@Api(tags = "阿里云上传图片接口")
public class UploadController {
    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/upload")
    @ApiOperation("上传图片到阿里云oss")
    public Result upload(MultipartFile image) throws IOException {
        log.info("文件上传",image.getOriginalFilename());
        //阿里云oss上传
        String url = aliOSSUtils.upload(image);
        log.info("文件上传完成",url);
        return Result.success(url);
    }
}
